using System;
using Microsoft.SPOT;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace GizmoProject
{
    /*
     */
    class MovementManager
    {
        private static MovementManager instance;
        private PWM leftMotor;
        private PWM rightMotor;

        private MovementManager()
        {
            this.leftMotor = new PWM( ( PWM.Pin )FEZ_Pin.PWM.Di6 );
            this.rightMotor = new PWM( ( PWM.Pin )FEZ_Pin.PWM.Di9 );
        }

        public static MovementManager Instance
        {
            get
            {
                if ( instance == null )
                    instance = new MovementManager();

                return instance;
            }
        }

        public void Stop()
        {
            leftMotor.Set( 0, 25 );
            rightMotor.Set( 0, 25 );

            /*
             * http://www.tinyclr.com/support
             * http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/Index.html
             *  PWM servo = new PWM( ( PWM.Pin )FEZ_Pin.PWM.Di6 );
            while ( true )
            {
                servo.Set( 1000, 25 );

                // 0 degrees. 20ms period and 1.25ms high pulse
               // servo.SetPulse( 20 * 1000 * 1000, 1250 * 1000 );
                Thread.Sleep( 5000 );//wait for a second


                servo.Set( 0, 75 );
                Thread.Sleep( 5000 );


                servo.Set( 1000, 75 );
                Thread.Sleep( 5000 );
             */
        }

        public void GoForward()
        {
            leftMotor.Set( 1000,  33); // 37 - go forward - LEFT
            rightMotor.Set( 1000, 97 ); //97 - go forlard - RIGHT
        }

        public void GoBackward()
        {
        }

        // Only turn
        public void TurnLeft()
        {
            leftMotor.Set( 0, 25 );
            rightMotor.Set( 1000, 97 );
        }

        // Only turn
        public void TurnRight()
        {
            rightMotor.Set( 0, 25 );
            leftMotor.Set( 1000, 31 );
        }
    }
}
